namespace AdminSG3L.Applicaticn.ServicesInterface;

using AdminSG3L.Domain.Entities;
using AdminSG3L.Applicaticn.Commands;
using AdminSG3L.Applicaticn.Dtos;

/// <summary>
/// 用户服务接口，定义用户相关的应用层操作
/// </summary>
public interface IUserService
{
    /// <summary>
    /// 创建新用户
    /// </summary>
    Task<ApiResponse<UserDto>> CreateAsync(CreateUserDto dto);

    /// <summary>
    /// 批量添加用户
    /// </summary>
    Task<ApiResponse<IEnumerable<UserDto>>> BatchCreateAsync(IEnumerable<CreateUserDto> dtos);

    /// <summary>
    /// 更新用户信息
    /// </summary>
    Task<ApiResponse<bool>> UpdateAsync(UpdateUserDto dto);

    /// <summary>
    /// 删除用户
    /// </summary>
    Task<ApiResponse<bool>> DeleteAsync(Guid id);

    /// <summary>
    /// 批量删除用户
    /// </summary>
    Task<ApiResponse<int>> BatchDeleteAsync(IEnumerable<Guid> ids);

    /// <summary>
    /// 查询所有用户
    /// </summary>
    Task<ApiResponse<IEnumerable<UserDto>>> GetAllDtoAsync();

    /// <summary>
    /// 分页查询用户
    /// </summary>
    Task<ApiResponse<(IEnumerable<UserDto> Users, int TotalCount)>> GetPagedDtoAsync(int pageIndex, int pageSize);

    /// <summary>
    /// 分页查询用户（包含角色信息）
    /// </summary>
    Task<ApiResponse<(IEnumerable<UserWithRolesDto> Users, int TotalCount)>> GetPagedWithRolesAsync(int pageIndex, int pageSize);

    /// <summary>
    /// 分页查询用户（包含角色信息和筛选条件）
    /// </summary>
    Task<ApiResponse<(IEnumerable<UserWithRolesDto> Users, int TotalCount)>> GetPagedWithRolesAsync(
        int pageIndex, 
        int pageSize,
        string? username = null,
        string? email = null,
        Guid? roleId = null,
        bool? isActive = null,
        DateTime? startDate = null,
        DateTime? endDate = null);

    /// <summary>
    /// 获取用户总数
    /// </summary>
    Task<ApiResponse<int>> GetCountAsync();

    /// <summary>
    /// 条件查询单个用户
    /// </summary>
    Task<ApiResponse<UserDto?>> FindOneAsync(Func<UserDto, bool> predicate);

    /// <summary>
    /// 条件查询多个用户
    /// </summary>
    Task<ApiResponse<IEnumerable<UserDto>>> FindManyAsync(Func<UserDto, bool> predicate);

    /// <summary>
    /// 根据ID获取用户实体
    /// </summary>
    Task<ApiResponse<AppUser?>> GetByIdAsync(Guid id);

    /// <summary>
    /// 给用户分配角色
    /// </summary>
    Task<ApiResponse<bool>> AssignRoleAsync(Guid userId, Guid roleId);

    /// <summary>
    /// 移除用户角色
    /// </summary>
    Task<ApiResponse<bool>> RemoveRoleAsync(Guid userId, Guid roleId);

    /// <summary>
    /// 修改用户启用状态
    /// </summary>
    Task<ApiResponse<bool>> SetEnabledAsync(Guid userId, bool enabled);

    /// <summary>
    /// 根据ID获取用户信息
    /// </summary>
    Task<ApiResponse<UserDto?>> GetDtoByIdAsync(Guid id);

    /// <summary>
    /// 根据ID获取用户信息（包含角色信息）
    /// </summary>
    Task<ApiResponse<AppUser?>> GetByIdWithIncludeAsync(Guid id);

    /// <summary>
    /// 重置用户密码
    /// </summary>
    Task<ApiResponse<bool>> ResetPasswordAsync(Guid userId, string newPassword);

    /// <summary>
    /// 修改用户密码
    /// </summary>
    Task<ApiResponse<bool>> ChangePasswordAsync(Guid userId, string oldPassword, string newPassword);
} 